﻿@model mesoBoard.Framework.Models.ViewThreadViewModel
           
@{
    Layout = "~/Views/Shared/_Site.cshtml";
}

@section BreadCrumbContent {
    @Html.ActionLink("Board Index", "Index", "Board")    
    &raquo;
    @Html.ActionLink(Model.Thread.Forum.Category.Name, "Index", "Board")    
    &raquo;
    @Html.ActionLink(Model.Thread.Forum.Name, "ViewForum", "Board", new { ForumID = Model.Thread.Forum.ForumID }, null)       
    &raquo;
    @Html.ActionLink(Model.Thread.Title, "ViewThread", "Board", new { ThreadID = Model.Thread.ThreadID }, new { @class = "current" })
}



<div class="view_thread @(Model.Thread.IsLocked ? "locked" : "")">    
        
    <div class="header">
    
        <div class="create">
            @(Html.ActionLink(
                    Model.Thread.IsLocked ? "Locked" : "Post Reply",
                    "CreatePost",
                    new { controller = "Post", threadID = Model.Thread.ThreadID },
                    new { @class = "create_post link_button" }))
        </div>

        @if (Model.Pagination.TotalPages != 1)
        {
            <div class="_Pagination">
                    @Html.Partial("_Pagination", Model.Pagination) 
            </div>
        } 
            
        <div class="details">
            <div class="title">
                Thread: 
                @if (!string.IsNullOrWhiteSpace(Model.Thread.Image))
                { 
                    <img src="@Url.Content("~/Images/ThreadImages/" + Model.Thread.Image) " alt="" />
                } 
                
                @Html.ActionLink(Model.Thread.Title, "ViewThread", new { controller = "Board", ThreadID = Model.Thread.ThreadID })
            </div>

            <div class="actions">
                @if (Model.ThreadActions.CanLock)
                { 
                    @(Html.ActionLink(
                            Model.Thread.IsLocked ? "Unlock Thread" : "Lock Thread",
                            "ToggleThreadLock",
                            new { ThreadID = Model.Thread.ThreadID },
                            new { @class = (Model.Thread.IsLocked ? "unlock_thread" : "lock_thread") + " link_button" }))
                } 
                @(Html.ActionLink(
                        Model.IsSubscribed ? "Unsubscribe to thread" : "Subscribe to thread",
                        "ToggleThreadSubscription",
                        new { threadID = Model.Thread.ThreadID },
                        new { @class = (Model.IsSubscribed ? "unsubscribe_thread" : "subscribe_thread") + " link_button" }))
            </div>   
        </div>         
    </div>

    @if (Model.Thread.HasPoll)
    { 
        <div class="poll">
                @Html.Partial("_ThreadPoll", Model.ThreadPoll)
        </div>
    } 
        
    <div class="posts">
        @foreach (var postRow in Model.Posts){
            @Html.Partial("_PostRow", postRow) 
        }
    </div>

    <div class="footer">
            
        <div class="details">
            <div class="title">
                Thread: 
                @if (!string.IsNullOrWhiteSpace(Model.Thread.Image))
                { 
                    <img src="@Url.Content("~/Images/ThreadImages/" + Model.Thread.Image) " alt="" />
                } 
                    
                @Html.ActionLink(Model.Thread.Title, "ViewThread", "Board", new { ThreadID = Model.Thread.ThreadID })
            </div>

            <div class="actions">
                @if (Model.ThreadActions.CanLock)
                { 
                    @(Html.ActionLink(
                            Model.Thread.IsLocked ? "Unlock thread" : "Lock thread",
                            "ToggleThreadLock",
                            new { ThreadID = Model.Thread.ThreadID },
                            new { @class = (Model.Thread.IsLocked ? "unlock_thread" : "lock_thread") + " link_button" }))
                } 
                @(Html.ActionLink(
                        Model.IsSubscribed ? "Unsubscribe to thread" : "Subscribe to thread",
                        "ToggleThreadSubscription",
                        new { threadID = Model.Thread.ThreadID },
                        new { @class = (Model.IsSubscribed ? "unsubscribe_thread" : "subscribe_thread") + " link_button" }))
            </div>   
        </div>         

        <div class="create">
            @(Html.ActionLink(
                    Model.Thread.IsLocked ? "Locked" : "Post Reply",
                    "CreatePost",
                    new { controller = "Post", threadID = Model.Thread.ThreadID },
                    new { @class = "create_post link_button" }))
        </div>

        @if (Model.Pagination.TotalPages != 1)
        {
            <div class="_Pagination">
                    @Html.Partial("_Pagination", Model.Pagination) 
            </div>
        } 

        @if (User.Identity.IsAuthenticated && !Model.Thread.IsLocked)
        {
            <div class="quick_reply">
                @using (Html.BeginForm("PostValidate", "Post"))
                { 
                <h3>Quick Reply</h3>
                <div style="">
                    <textarea cols="60" rows="7" class="bbcode"  name="PostEditor.Message"></textarea>
                    @Html.ValidationMessage("PostEditor.Message") 
                    @Html.Hidden("ThreadID", Model.Thread.ThreadID)
                    @Html.AntiForgeryToken() 
                    <input type="submit" value="Post Reply" />
                </div>
                } 
            </div>
        } 
    </div>
</div>